package com.example.demo.controller;

import com.example.demo.service.SectionService;
import com.example.demo.utils.R;
import com.example.demo.utils.ReSet;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
public class SectionController {

    @Resource
    private SectionService sectionService;

    /**
     * 增加小节
     * */
    @PostMapping("inssec")
    public R inssec(String section_name, Integer chapter_id){
        int i = sectionService.inssec(section_name,chapter_id);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }

    /**
     * 查看小节
     * */
    @PostMapping("selsec")
    public R selsec(Integer chapter_id){
        List list = sectionService.selsec(chapter_id);
        if (list != null){
            return ReSet.Ok(list);
        }
        return ReSet.Err();

    }

    /**
     * 更改小节
     * */
    @PostMapping("updatesection")
    public R updatesection(String section_name, Integer section_id){
        int i = sectionService.updatesection(section_name,section_id);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }

    /**
     * 更改小节状态
     * */
    @PostMapping("upsectype")
    public R upsectype(Integer section_type, Integer section_id){
        int i = sectionService.upsectype(section_type,section_id);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }

    /**
     * 删除小节
     * */
    @PostMapping("delsec")
    public R delsec(Integer section_id){
        int i = sectionService.delsec(section_id);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }

}
